 package server.quest;

 import client.MapleCharacter;
 import client.MapleQuestStatus;
 import client.inventory.Item;
 import client.inventory.MapleInventoryType;
 import client.skills.Skill;
 import client.skills.SkillFactory;
 import constants.ItemConstants;
 import java.io.Serializable;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.List;
 import tools.Pair;

 public class MapleQuestReward
   implements Serializable
 {
   private static final long serialVersionUID = 9179541993413738569L;
   private final MapleQuestRewardType type;
/*  22 */   private final List<Pair<Integer, Integer>> dataStore = new ArrayList<>();




   private int intStore;




   public MapleQuestReward(MapleQuestRewardType type, ResultSet rse) throws SQLException {
/*  33 */     this.type = type;
/*  34 */     if (type == MapleQuestRewardType.item) {
/*  35 */       this.dataStore.add(new Pair(Integer.valueOf(rse.getInt("itemId")), Integer.valueOf(rse.getInt("num"))));
     }
   }







   public boolean getRewardToChr(MapleCharacter chr) {
/*  46 */     switch (this.type) {
       case item:
/*  48 */         for (Pair<Integer, Integer> a : this.dataStore) {
/*  49 */           int itemId = ((Integer)a.getLeft()).intValue();
/*  50 */           short quantity = 0;
/*  51 */           MapleInventoryType iType = ItemConstants.getInventoryType(itemId);
/*  52 */           for (Item item : chr.getInventory(iType).listById(itemId)) {
/*  53 */             quantity = (short)(quantity + item.getQuantity());
           }
/*  55 */           int count = ((Integer)a.getRight()).intValue();
/*  56 */           if (quantity < count || (count <= 0 && quantity > 0)) {
/*  57 */             return false;
           }
/*  59 */           chr.gainItem(itemId, count, "任务获得道具！");
         }
/*  61 */         return true;
     }
/*  63 */     return true;
   } public boolean check(MapleCharacter chr, Integer npcid) {
     int[] partyQuests;
     int sRankings;
/*  67 */     switch (this.type) {
       case job:
/*  69 */         for (Pair<Integer, Integer> a : this.dataStore) {
/*  70 */           if (((Integer)a.getRight()).intValue() == chr.getJob() || chr.isGM()) {
/*  71 */             return true;
           }
         }
/*  74 */         return false;
       case skill:
/*  76 */         for (Pair<Integer, Integer> a : this.dataStore) {
/*  77 */           boolean acquire = (((Integer)a.getRight()).intValue() > 0);
/*  78 */           int skill = ((Integer)a.getLeft()).intValue();
/*  79 */           Skill skil = SkillFactory.getSkill(skill);
/*  80 */           if (acquire) {
/*  81 */             if (chr.getSkillLevel(skil) == 0)
/*  82 */               return false;  continue;
           }
/*  84 */           if (chr.getSkillLevel(skil) > 0 || chr.getMasterLevel(skil) > 0) {
/*  85 */             return false;
           }
         }
/*  88 */         return true;
       case quest:
/*  90 */         for (Pair<Integer, Integer> a : this.dataStore) {
/*  91 */           MapleQuestStatus q = chr.getQuest(MapleQuest.getInstance(((Integer)a.getLeft()).intValue()));
/*  92 */           int state = ((Integer)a.getRight()).intValue();
/*  93 */           if (state == 0 || (
/*  94 */             q == null && state == 0)) {
             continue;
           }
/*  97 */           if (q == null || q.getStatus() != state) {
/*  98 */             return false;
           }
         }

/* 102 */         return true;
       case item:
/* 104 */         for (Pair<Integer, Integer> a : this.dataStore) {
/* 105 */           int itemId = ((Integer)a.getLeft()).intValue();
/* 106 */           short quantity = 0;
/* 107 */           MapleInventoryType iType = ItemConstants.getInventoryType(itemId);
/* 108 */           for (Item item : chr.getInventory(iType).listById(itemId)) {
/* 109 */             quantity = (short)(quantity + item.getQuantity());
           }
/* 111 */           int count = ((Integer)a.getRight()).intValue();
/* 112 */           if (quantity < count || (count <= 0 && quantity > 0)) {
/* 113 */             return false;
           }
         }
/* 116 */         return true;
       case lvmin:
/* 118 */         return (chr.getLevel() >= this.intStore);
       case lvmax:
/* 120 */         return (chr.getLevel() <= this.intStore);

       case mob:
/* 123 */         return true;
       case npc:
/* 125 */         return (npcid == null || npcid.intValue() == this.intStore);
       case fieldEnter:
/* 127 */         return (this.intStore <= 0 || this.intStore == chr.getMapId());
       case pop:
/* 129 */         return (chr.getFame() >= this.intStore);
       case questComplete:
/* 131 */         return (chr.getNumQuest() >= this.intStore);
       case partyQuest_S:
/* 133 */         partyQuests = new int[] { 1200, 1201, 1202, 1203, 1204, 1205, 1206, 1300, 1301, 1302 };
/* 134 */         sRankings = 0;
/* 135 */         for (int i : partyQuests) {
/* 136 */           String rank = chr.getOneInfo(i, "rank");
/* 137 */           if (rank != null && rank.equals("S")) {
/* 138 */             sRankings++;
           }
         }
/* 141 */         return (sRankings >= 5);
       case subJobFlags:
/* 143 */         return (chr.getSubcategory() == this.intStore / 2);
     }








/* 153 */     return true;
   }

   public MapleQuestRewardType getType() {
/* 157 */     return this.type;
   }


   public String toString() {
/* 162 */     return this.type.toString();
   }

   public List<Pair<Integer, Integer>> getDataStore() {
/* 166 */     return this.dataStore;
   }
 }


/* Location:              C:\PGX\Server.jar!\server\quest\MapleQuestReward.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */